//
//  NewsDetailViewController.m
//  Conference
//
//  Created by 陈鑫 on 12-11-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "NewsDetailViewController.h"
#import "NewsData.h"
#import "Globals.h"
#import "AsyncImageView.h"
#import "NetContant.h"
@interface NewsDetailViewController ()

@end

@implementation NewsDetailViewController
@synthesize lab_coming;
@synthesize lab_title;
@synthesize lab_time;
@synthesize lab_content;
@synthesize newsData;
@synthesize scrollView;
@synthesize Height;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    
    self.lab_title.text=self.newsData.title;
    self.lab_coming.text=[NSString stringWithFormat:@"来源：%@",self.newsData.writer];
    self.lab_time.text=self.newsData.dateTime;
    
    
    NSString *content=[NSString stringWithFormat:@"%@",self.newsData.message];
    
    UIFont *font = [UIFont systemFontOfSize:16];
    
    CGSize size=[[Globals getInstance]CalculationCellSize:self.scrollView.frame.size.width fontSize:16 content:content];
    
    CGRect rect = [self.lab_content textRectForBounds:self.lab_content.frame limitedToNumberOfLines:0];
    rect.size=size;
    self.lab_content.frame = rect;
    self.lab_content.text=content;
    self.lab_content.numberOfLines = 0;
    self.lab_content.font = font;
    
  
    [self.scrollView setContentSize:CGSizeMake(260, size.height)];
    //
    self.Height=size.height+20;
    NSString *imgUri=self.newsData.arrImg;
    
    if(nil!=imgUri||![imgUri isEqualToString:@""]){
        NSArray *img=[imgUri componentsSeparatedByString:[NetContant getInstance].IMGURL_SPLIT_FLAG];
        for(int i=0;i<[img count];i++){
            NSString *sImg=[img objectAtIndex:i];
            if (nil == sImg || [@"" isEqualToString:sImg])
                continue;
            AsyncImageView *asyncImage = [[AsyncImageView alloc] init];
            //int width=asyncImage
            asyncImage.frame = CGRectMake(20, self.Height,220, 220);
            [asyncImage loadImageFromURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[Globals getInstance].servierUrl,sImg]]];
            self.Height=self.Height+asyncImage.frame.size.height;
            [self.scrollView addSubview:asyncImage];
            [asyncImage release];
        }
    [self.scrollView setContentSize:CGSizeMake(260, self.Height)];
    }

    
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [self setNewsData:nil];
    [self setLab_title:nil];
    [self setLab_time:nil];
    [self setLab_content:nil];
    [self setScrollView:nil];
    [self setLab_coming:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [newsData release];
    [lab_title release];
    [lab_time release];
    [lab_content release];
    [scrollView release];
    [lab_coming release];
    [super dealloc];
}
- (IBAction)btnBackAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
